package com.itheima.edu.info.student.manager.service;

import com.itheima.edu.info.student.manager.dao.TeacherDao;
import com.itheima.edu.info.student.manager.domain.Teacher;

public class TeacherService {


    TeacherDao tdao = new TeacherDao();


    public boolean addTeacher(Teacher tea) {
        return tdao.addTeacher(tea);
    }

    public Teacher[] findAllteacher() {
        //调用库管类的方法,返回系统容器数组,创建一个数组接收
        Teacher[] teas = tdao.findAllteacher();
        //使用标记位方法,判断数组容器是否已经存入元素
        boolean flag = false;
        //遍历数组
        for (int i = 0; i < teas.length; i++) {
            //如过当前元素不为null值,说明数组容器中已经存入数据,令标记位记录true
            if (teas[i]!=null){
                flag = true;
            }
        }if(flag){
            return teas;
        }else{
            return null;
        }

    }

    public boolean isExists(String updateId) {
       Teacher[] teas = tdao.findAllteacher();

       //使用标记位思想判断id是否存在,先假设要修改的学生id不存在
        boolean flag = false;
        //遍历数组
        for (int i = 0; i < teas.length; i++) {
            if (teas[i]!=null&&updateId.equals(teas[i].getId())){
                flag = true;
            }
        }return flag;



    }

    public void updateTeacher(String updateId, Teacher tea) {
        tdao.updateTeacher(updateId,tea);

    }

    public void deleteTeacher(String id) {
        tdao.deleteTeacher(id);


    }
}
